package com.hxkcloud.nurse.request;

import com.hxkcloud.nurse.YjhApplication;
import com.hxkcloud.nurse.beans.LoginInfo;
import com.hxkcloud.nurse.beans.RequestSecdataBean;
import com.hxkcloud.nurse.dborm.LoginInfoDao;

import java.util.HashMap;
import java.util.Map;

/**
 * @Package: com.yipong.app.request
 * @ClassName: BaseParams.java
 * @Description:基础参数封装
 * @auther: allen_lee
 * @Date: 2016-2-25 下午6:22:36
 */

public abstract class BaseParams {

    // 用来存储get参数集合
    protected static Map<String, Object> getParameter = null;
    // 用来存储post参数集合
    protected static Map<String, Object> postParameter = null;

    /**
     * @param needSecData 是否需要添加secData
     */
    protected static void instance(boolean needSecData) {
        getParameter = new HashMap<String, Object>();
        postParameter = new HashMap<String, Object>();
        if (needSecData) {
            postParameter.put("Secdata", getSecdata());
        }

    }

    private static RequestSecdataBean getSecdata() {

        if (YjhApplication.secData == null) {
            YjhApplication.initSecData();
        }

        LoginInfoDao loginDao = new LoginInfoDao(YjhApplication.applicationContext);
        LoginInfo info = loginDao.getUser(); //StorageManager.getInstance(YjhApplication.applicationContext).getUserLoginInfo();

        if (info != null) {
            YjhApplication.secData.setToken(info.getToken());
            YjhApplication.secData.setUser_id(info.getUserId());
//            YjhApplication.secData.setUser_id("7895eace27cb4cbfb026c55d7d19c837");
            YjhApplication.secData.setUsername(info.getName());
            YjhApplication.secData.setUser_type(info.getUserStyle());
//            YjhApplication.secData.setUser_type("4");
        }
        return YjhApplication.secData;

    }
}
